<?php

  include_once "lib.inc.php";

  define("__CODE_200", "PHP/" . phpversion() . "_E/200_OK");
  define("__CODE_204", "PHP/" . phpversion() . "_E/204_NO_REQUEST");
  define("__CODE_400", "PHP/" . phpversion() . "_E/400_BAD_REQUEST");
  define("__CODE_404", "PHP/" . phpversion() . "_E/404_CLASS_NOT_FOUND");
  define("__CODE_405", "PHP/" . phpversion() . "_E/405_ACTION_NOT_SET");
  define("__CODE_501", "PHP/" . phpversion() . "_E/501_FUNCTION_NOT_IMPLEMENTED");

  if (isset($_POST["object"]) && !empty($_POST['object'])) {
    if ($_POST["object"] == "version") {
      print __CODE_200;
    } else {
      $Object = NULL;
      $ClassController = "";
      $Controller = NULL;
      $Object = @unserialize(trim(stripslashes(urldecode($_POST['object']))));

      if ($Object) {
        $ClassController = eregi_replace("Model", "Controller", ucfirst(get_class($Object)));

        if ($ClassController != "__PHP_Incomplete_Class") {
          $Controller = new $ClassController($Object);

          if ($Object->getAction() != null) {
            if (method_exists($Object, "getAction") && method_exists($Controller, $Object->getAction()->toString()) && method_exists($Controller, "getObject")) {
              $Controller->{$Object->getAction()->toString()}();
              print urlencode(serialize($Controller->getObject()));
            } else {
              print __CODE_501;
            }
          } else {
            print __CODE_405;
          }
        } else {
          print __CODE_404;
        }
      } else {
        print __CODE_400;
      }
    }
  } else {
    print __CODE_204;
  }
?>